extends Enemy

func hurt():
	$AnimatedSprite2D.play("death")
	$CollisionShape2D.shape.size.y /= 2
	$CollisionShape2D.position.y += $CollisionShape2D.shape.size.y
	$Area2D/CollisionShape2D2.shape.size.y /= 2
	$Area2D/CollisionShape2D2.position.y += $Area2D/CollisionShape2D2.shape.size.y
	direction = 0
	var score_label = SCORE.instantiate()
	score_label.text = "100"
	add_child(score_label)
	$Area2D/CollisionShape2D2.set_deferred("disabled",true)
	$CollisionShape2D.set_deferred("disabled",true)
	velocity.y = dead_speed
	get_tree().create_timer(3.0).timeout.connect(queue_free)
	pass

func _on_area_2d_body_entered(body):
	if body.is_in_group("block") or body.is_in_group("pip"):
		direction = -direction
	elif body.is_in_group("player"):
		if body.global_position.y - global_position.y < -10:
			hurt()
			body.trample_enemy()
		else:
			body.hurt()
